<?php
/*
Copyright (C) 2009 de Flotte Maxence

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
?>
<?php
/**
 * Get urls
 */
class ZzGetUrl {
	/**
	* Get the url of the current page with new get params
	* @param string $gKey get param
	* @param string $gVal get value
	* @return string
	*/
	static function with($gKey = null,$gVal = null) {
		$url = '?';
		if(isset($_GET[$gKey])) {
			$_GET[$gKey] = $gVal;
			$gKey = null;
		}
		foreach($_GET As $key => $val)
			$url .= $key.'='.$val.'&';
		if($gKey != null) {
			$url .= $gKey.'='.$gVal;
		}
		return $url;
	}

	/**
	* Get the url of a child
	* @param string $arg Child lid
	* @param bool $altPuZZle Is it an alternatif puzzle ?
	* @return string
	*/
	static function childLabel($arg,$altPuZZle = false) {
		if($altPuZZle)
			return './?label='.$arg.'-'.$_GET['label'].'&altPuZZle';
		else
			return './?label='.$arg.'-'.$_GET['label'];
	}

	/**
	* Get the parent url
	* @param bool $altPuZZle Is it an alternatif puzzle ?
	* @return string
	*/
	static function parentLabel($altPuZZle = false) {
			$_labels = explode('-',$_GET['label']);
			array_splice($_labels,0,1);
			$url = implode('-',$_labels);
			if($altPuZZle)
				$url .= '&altPuZZle';
			return './?label='.$url;
	}

	/**
	* Get the url of the current label, but for other puzzle.
	* @return string
	*/
	static function theOtherPuZZle() {
		if(isset($_GET['altPuZZle']))
			if($_GET['altPuZZle'] == 'true')
				return './?label='.$_GET['label'];
		return './?label='.$_GET['label'].'&altPuZZle';
	}
}
?>
